package com.travelshare.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.travelshare.common.annotation.Log;
import com.travelshare.common.core.controller.BaseController;
import com.travelshare.common.core.domain.AjaxResult;
import com.travelshare.common.enums.BusinessType;
import com.travelshare.business.domain.DetailReview;
import com.travelshare.business.service.IDetailReviewService;
import com.travelshare.common.utils.poi.ExcelUtil;

/**
 * 用户文章评论Controller
 * 
 * @author travelshare
 * @date 2024-03-05
 */
@RestController
@RequestMapping("/business/detailReview")
public class DetailReviewController extends BaseController
{
    @Autowired
    private IDetailReviewService detailReviewService;

    /**
     * 查询用户文章评论列表
     */
    //@PreAuthorize("@ss.hasPermi('business:detailReview:list')")
    @GetMapping("/list")
    public AjaxResult list(DetailReview detailReview)
    {
        List<DetailReview> list = detailReviewService.selectDetailReviewList(detailReview);
        return success(list);
    }

    /**
     * 导出用户文章评论列表
     */
    @PreAuthorize("@ss.hasPermi('business:detailReview:export')")
    @Log(title = "用户文章评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DetailReview detailReview)
    {
        List<DetailReview> list = detailReviewService.selectDetailReviewList(detailReview);
        ExcelUtil<DetailReview> util = new ExcelUtil<DetailReview>(DetailReview.class);
        util.exportExcel(response, list, "用户文章评论数据");
    }

    /**
     * 获取用户文章评论详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:detailReview:query')")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(detailReviewService.selectDetailReviewByReviewId(reviewId));
    }

    /**
     * 新增用户文章评论
     */
    //@PreAuthorize("@ss.hasPermi('business:detailReview:add')")
    @Log(title = "用户文章评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DetailReview detailReview)
    {
    	detailReview.setDelFlag("0");
    	detailReview.setUserId(getUserId());
    	detailReview.setCreateBy(getNickname());
        return toAjax(detailReviewService.insertDetailReview(detailReview));
    }

    /**
     * 修改用户文章评论
     */
    @PreAuthorize("@ss.hasPermi('business:detailReview:edit')")
    @Log(title = "用户文章评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DetailReview detailReview)
    {
        return toAjax(detailReviewService.updateDetailReview(detailReview));
    }

    /**
     * 删除用户文章评论
     */
    @PreAuthorize("@ss.hasPermi('business:detailReview:remove')")
    @Log(title = "用户文章评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(detailReviewService.deleteDetailReviewByReviewIds(reviewIds));
    }
    
    @GetMapping("/detailReviewTree")
    public AjaxResult detailReviewTree(DetailReview detailReview)
    {
        return success(detailReviewService.selectDetailReviewTreeList(detailReview));
    }
}
